class Solution {
public:
    vector<int> countBits(int n) {

        vector<int> ret;
        for(int i=0;i<=n;++i)
        {
            int a=0;
            int x=i;
            int count=0;
            while(x)
            {
                x&=(x-1);
                count++;
            }
            ret.push_back(count);
        }
        return ret;
    }
};
